﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace eShop.DataAccess.Converter
{
    public class UserConverter
    {
        public static List<Model.User> ConvertToModelObject(List<Entity.User> entities)
        {
            List<Model.User> models = new List<Model.User>(entities.Count);
            foreach (Entity.User entity in entities)
            {
                models.Add(ConvertToModelObject(entity));
            }
            return models;
        }

        public static Model.User ConvertToModelObject(Entity.User entity)
        {
            if (entity == null) return null;
            Model.User model = new Model.User();
            model.Id = entity.Id;
            model.UserName = entity.UserName;
            model.Password = entity.Password;
            model.Role = (Model.UserRoleType)Enum.Parse(typeof(Model.UserRoleType), entity.Role);
            model.CreatedOn = entity.CreatedOn;
            model.IsActive = entity.IsActive;
            return model;
        }

        public static Entity.User ConvertToEntity(Model.User model)
        {
            Entity.User entity = new Entity.User();
            entity.Id = model.Id;
            entity.UserName = model.UserName;
            entity.Password = model.Password;
            entity.Role = model.Role.ToString();
            entity.CreatedOn = model.CreatedOn;
            entity.IsActive = model.IsActive;
            return entity;
        }
    }
}
